package com.framework2.utils;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.asiainfo.hybridapp.R;
import com.framework2.customLoading.LoadingDialog;

/**
 * 自定义对话框
 */
public class CustomProgressDialog extends ProgressDialog {

    private String mLoadingTip;
    private TextView mLoadingTv;
    private LoadingDialog customLoadingView;

    public CustomProgressDialog(Context context, String content) {
        super(context);
        this.mLoadingTip = content;
        setCanceledOnTouchOutside(false);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        initData();
    }

    private void initData() {
        mLoadingTv.setText(mLoadingTip);
        Window window = getWindow();
//        window.setBackgroundDrawable(new ColorDrawable(Color.argb(255, 255, 255, 255)));
        window.setBackgroundDrawable(new ColorDrawable(0));
    }

    public void setContent(String str) {
        if (TextUtils.isEmpty(str)) {
            mLoadingTv.setVisibility(View.GONE);
        } else {
            mLoadingTv.setVisibility(View.VISIBLE);
            mLoadingTv.setText(str);
        }
    }

    private void initView() {
        setContentView(R.layout.progress_dialog);
        mLoadingTv = (TextView) findViewById(R.id.loadingTv);
        customLoadingView = (LoadingDialog) findViewById(R.id.customLoadingView);
        customLoadingView.setState(LoadingDialog.State.Loading);
        if (TextUtils.isEmpty(mLoadingTip)) {
            mLoadingTv.setVisibility(View.GONE);
        }
    }
}
